﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using wUniApp.MVC.Helpers;

namespace System.Web.Mvc
{
  public static class wHtmlHelpers
  {
    public static HtmlString SubmitSave(this HtmlHelper helper)
    {
      return Submit(helper, wUniApp.MVC.App_GlobalResources.Resources.Save);
    }
    public static HtmlString SubmitCreate(this HtmlHelper helper)
    {
      return Submit(helper, wUniApp.MVC.App_GlobalResources.Resources.Create);
    }
    public static HtmlString Submit(this HtmlHelper helper, string text)
    {
      string res =
        "<div class=\"form-group\">"
      + "  <div class=\"col-md-offset-2 col-md-10\">"
      + "    <input type=\"submit\" value=\"" + text + "\" class=\"btn btn-default\" />"
      + "  </div>"
      + "</div>";

      return new HtmlString(res);
    }

    public static HtmlString EDDButtons(this HtmlHelper helper, object itemId)
    {
      string res =
        Html.LinkExtensions.ActionLink(helper, wUniApp.MVC.App_GlobalResources.Resources.Edit, "Edit", new { id = itemId }).ToHtmlString()
        + " | "
        + Html.LinkExtensions.ActionLink(helper, wUniApp.MVC.App_GlobalResources.Resources.Details, "Details", new { id = itemId }).ToHtmlString()
        + " | "
        + Html.LinkExtensions.ActionLink(helper, wUniApp.MVC.App_GlobalResources.Resources.Delete, "Delete", new { id = itemId }).ToHtmlString();
      return new HtmlString(res);
    }

    public static HtmlString CreateNew(this HtmlHelper helper)
    {
      string res = 
        Html.LinkExtensions.ActionLink(helper, wUniApp.MVC.App_GlobalResources.Resources.CreateNew, "Create").ToHtmlString();
      return new HtmlString(res);
    }

    public static HtmlString BackToList(this HtmlHelper helper)
    {
      string res =
        Html.LinkExtensions.ActionLink(helper, wUniApp.MVC.App_GlobalResources.Resources.BackToList, "Index").ToHtmlString();
      return new HtmlString(res);
    }

    public static HtmlString GetTitle(this HtmlHelper helper)
    {
      string title = (string) helper.ViewBag.Title;
      string res =
       String.Format("<h2>{0}</h2>", title);
      return new HtmlString(res);
    }

    public static HtmlString GroupByLink(this HtmlHelper helper, string columnName, string actionName, string controllerName)
    {
      string title = wLangHelper.GetLocText(columnName);
      string res =
        Html.LinkExtensions.ActionLink(helper, title, actionName, controllerName, new { ColumnName = columnName }, null).ToHtmlString();
      return new HtmlString(res);
    }
  }
}